<?php
session_start();

require_once 'response.php';
require_once 'connect_config.php';
require('../config.php');

/*---------------------变量参数定义-------------------------------*/
$token = $_GET['token'];
if(!$token)
{
	$username=$_SESSION['username'];
	$firstname=$_GET['firstname'];
	$lastname=$_GET['lastname'];
	$country=$_GET['country'];
	$city=$_GET['city'];
	$email=$_GET['email'];
	$phone1=$_GET['phone1'];
	$phone2=$_GET['phone2'];
}

$status = false;
$msg = '';
$data = array();
echo "start";


//数据库连接
$conn = mysqli_connect(DB_HOST,DB_USER,DB_PWD,DB_NAME,DB_PORT) or die('数据库连接失败');

//查询用户ID
if($username)
{
	$query1 = "select * from mdl_user where username = '$username'";
	$data1 = mysqli_query($conn, $query1);
	$row1 = mysqli_fetch_array($data1);
	if ($row1)
	{
		$query = "insert into mdl_user (firstname,lastname,country,city,email,phone1,phone2) values ('$firstname','$lastname','$country,'$city','$email','$phone1','$phone2')";
         $result = mysqli_query($conn, $query);
		if($result==false)
		{
			$status = false;
			$msg = mysqli_errno($conn);
			echo Response::json($status,$msg,$data);	
		}
		else
		{
			$status = true;
			$msg = "success";
			echo Response::json($status,$msg,$data);
		}
	}
}
else if($token)
{
	$query1 = "select * from mdl_token where token = '$token'";
	$data1 = mysqli_query($conn, $query1);
	$row1 = mysqli_fetch_array($data1);
	if ($row1)
	{
		$userid=$row1['user_id'];
		$query2 = "select * from mdl_user where id = '$userid'";
		$data2 = mysqli_query($conn, $query2);
		$row2 = mysqli_fetch_array($data2);
		if ($row2)
		{
			$query = "insert into mdl_user (firstname,lastname,country,city,email,phone1,phone2) values ('$firstname','$lastname','$country,'$city','$email','$phone1','$phone2')";
			 $result = mysqli_query($conn, $query);
			if($result==false)
			{
				$status = false;
				$msg = mysqli_errno($conn);
				echo Response::json($status,$msg,$data);	
			}
			else
			{
				$status = true;
				$msg = "success";
				echo Response::json($status,$msg,$data);
			}
		}
	}
}



?>